package com.game.my.api;

import java.text.NumberFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.game.hall.model.GameUser;
import com.game.my.model.Account;
import com.game.my.model.GameInfo;
import com.game.my.model.GameNum;
import com.game.my.model.MyMesage;
import com.jfinal.core.Controller;

public class MyMesageApi extends Controller {

	/**
	 * 我的个人信息
	 * 
	 * @return
	 */
	public void queryMesage() {

		String nickname = getPara("nickname");
		GameUser gu = GameUser.dao.getGameUserByNickName(nickname);

		Map<String, Object> map = new HashMap<String, Object>();
		MyMesage myMesage = MyMesage.dao.findByopId(gu.get("id"));// 我的基本信息
		map.put("myMesage", myMesage);// 我的基本信息
		Account account = Account.dao.getAcount(Long.parseLong(gu.get("id")
				.toString()));
		Double balance = account.getDouble("balance");
		map.put("balance", balance);// 账号余额

		List<GameInfo> gaminfoList = GameInfo.dao.getGameInfo(gu.get("id"));// 游戏信息
		map.put("gaminfoList", gaminfoList);

		List<Account> acountList = Account.dao.AccountList(gu.get("id"));// 账户信息
		map.put("acountList ", acountList);
		List<GameNum> querylist = GameNum.dao.gameNum(gu.get("id"));
		int num = querylist.size();
		map.put("num", num);// 游戏场次

		List<GameNum> queryCount = GameNum.dao.gameNum(1);
		List<GameNum> queryWin = GameNum.dao.gameWin(1);
		int couNum = queryCount.size();// 游戏场次
		int wiNum = queryWin.size();// 游戏胜场

		// 创建一个数值格式化对象
		NumberFormat numberFormat = NumberFormat.getInstance();
		// 设置精确到小数点后2位
		numberFormat.setMaximumFractionDigits(2);
		String result = numberFormat.format((float) wiNum / (float) couNum
				* 100);
		// float result = (float)wiNum/(float)couNum;
		if (wiNum == 0 || couNum == 0) {
			result = "0";
		}
		map.put("result", result);// 游戏胜率
		renderJson(map);
	}
}
